package com.nd.controller.admin;


import com.nd.pojo.bean.Coupon;
import com.nd.pojo.bo.*;
import com.nd.pojo.vo.AdQueryDataVo;
import com.nd.pojo.vo.BaseRespVo;
import com.nd.service.AdService;
import com.nd.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/coupon")
public class CouponController {

    @Autowired
    CouponService couponService;

    @RequestMapping("list")
    public BaseRespVo query(CouponQueryBo couponQueryBo){

        AdQueryDataVo couponDataVo = couponService.queryAll(couponQueryBo.getPage(), couponQueryBo.getLimit(),
                couponQueryBo.getSort(),couponQueryBo.getOrder(), couponQueryBo.getName(), couponQueryBo.getType(),
                couponQueryBo.getStatus());


        return BaseRespVo.ok(couponDataVo);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody CouponDeleteBo couponDeleteBo){

        Integer code = couponService.delete(couponDeleteBo);

        if (code == 1) {
            return BaseRespVo.ok();
        }

        return BaseRespVo.fail();
    }

    @RequestMapping("read")
    public BaseRespVo delete(Integer id){

        Coupon couponData = couponService.queryById(id);

        return BaseRespVo.ok(couponData);
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody Coupon coupon){

        Coupon coupon1 = couponService.create(coupon);

        if (coupon == null){
            BaseRespVo.fail("天数，总券数，打折不能为负数");

        }

        return BaseRespVo.ok(coupon1);
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Coupon coupon){

        Coupon coupon1 = couponService.update(coupon);

        if (coupon == null){
            BaseRespVo.fail("天数，总券数，打折不能为负数");

        }

        return BaseRespVo.ok(coupon1);

    }

    @RequestMapping("listuser")
    public BaseRespVo queryUser(CouponQueryUserBo couponQueryUserBo){

        AdQueryDataVo couponQueryUserDataVo = couponService.queryUser(couponQueryUserBo.getPage(), couponQueryUserBo.getLimit(),
                couponQueryUserBo.getSort(), couponQueryUserBo.getOrder(), couponQueryUserBo.getCouponId(), couponQueryUserBo.getUserId(),
                couponQueryUserBo.getStatus());


        return BaseRespVo.ok(couponQueryUserDataVo);
    }




}
